﻿using System.Text.Json;
using System.Text;
using WareHouseManagement.ModelEntity;
using WareHouseManagement.Commom;
namespace WareHouseManagement.Data
{
    public class InventoryServer
    {
        public async Task<Resultcurrent> MakeInventory(List<A07Par> a07Pars)
        {
            using (HttpClientHandler clientHandler = new HttpClientHandler())
            {
                clientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, error) => true;
                using (HttpClient client = new HttpClient(clientHandler))
                {
                    var request = new HttpRequestMessage(HttpMethod.Post, $"{AppSettingsJson.GetAppSettings().GetSection("ConnectionUrl")["DefaultConnection"]}/api/AG2WareHouse/UpdataAG2Warehouse");
                    request.Headers.Add("Accept", "text / plain");
                    try
                    {
                        var jsonPar = JsonSerializer.Serialize<List<A07Par>>(a07Pars);
                        request.Content = new StringContent(jsonPar, Encoding.UTF8, "application/json");
                        var response = await client.SendAsync(request);
                        if (response.IsSuccessStatusCode)
                        {
                            var stream = await response.Content.ReadAsStreamAsync();
                           var result = JsonSerializer.DeserializeAsync
                                  <Resultcurrent>(stream).Result;
                            return result;
                        }
                        else
                        {
                            return new Resultcurrent() { SUCCESS = 0, MESSAGE = "盘点失败" };
                            //  getBranchesError = true;
                        }
                    }
                    catch (Exception e)
                    {
                         
                        return new Resultcurrent() { SUCCESS = 0, MESSAGE = "盘点异常报错" };
                    }
                }
            }
        }
    
    }
}
